// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System.Text;

namespace SnapObjects.Data
{
    internal abstract class SqlRawStatementParser : SqlStatementParser
    {
        public SqlRawStatementParser(
            ISqlStatementFactory factory, ISqlGenerationHelper helper) : base(factory, helper)
        {

        }

        public override SqlStatement ParseStatement(ISqlTokenizer tokenizer, bool isClause)
        {
            _isClause = isClause;

            var sqlStatement = new SqlRawStatement();

            while (tokenizer.MoveNext())
            {
                if (tokenizer.Current is SqlParameterToken parameter)
                {
                    if (!sqlStatement.Parameters.ContainsKey(parameter.Name))
                    {
                        sqlStatement.Parameters.Add(parameter.Name, parameter);
                    }
                }

                sqlStatement.SqlRaw.Add(tokenizer.Current);
            }

            return sqlStatement;
        }
    }
}
